package com.situ.fly.controller.api;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.situ.fly.entity.Answer;
import com.situ.fly.entity.JSONResult;
import com.situ.fly.entity.User;
import com.situ.fly.service.AnswerService;

@RestController
@RequestMapping("/api/answer/")
public class APIAnswerController {

	@Autowired
	private AnswerService answerService;
	
	/**
	 * 获取回复信息
	 */
	@PostMapping("/get")
	public JSONResult get(Integer id) {
		
		Answer answer = answerService.getById(id);
		
		JSONResult json = new JSONResult();
		
		json.setData(answer);
		
		return json;
	}
	
	/**
	 * 修改回复
	 * 
	 */
	@PostMapping("/edit")
	public JSONResult edit(Answer answer) {
		
		int res = answerService.edit(answer);
		
		JSONResult json = new JSONResult();
		
		return json;
	}
	
	/**
	 * 删除解答
	 */
	@PostMapping("/delete")
	public JSONResult delete(Answer answer) {
		
		int res = answerService.delete(answer);
		
		JSONResult json = new JSONResult();
		
		return json;
	}
	
	/**
	 *  采纳
	 */
	@PostMapping("/accept")
	public JSONResult accept(Answer answer) {
		
		int res = answerService.accept(answer);
		
		JSONResult json = new JSONResult();
		
		return json;
	}
	
	/**
	 * 点赞
	 */
	@PostMapping("/like")
	public JSONResult like(Boolean ok, Integer id, HttpSession session) {
		User user = (User) session.getAttribute("user");
		
		int res = answerService.like(id, user.getId(), ok);
		
		JSONResult json = new JSONResult();
		
		return json;
	}
}
